package com.warm.core.bean;

import org.noear.solon.core.handle.Result;
import org.noear.solon.validation.BeanValidateInfo;
import org.noear.solon.validation.ValidatorException;
import org.noear.solon.validation.ValidatorManager;

/**
 * bean对象属性验证
 *
 * @author warm
 */
public class BeanValidators {
    public static void validate(Object obj, Class<?>[] groups) {
        Result result = ValidatorManager.validateOfEntity(obj, groups);
        if (Result.FAILURE_CODE == result.getCode()) {
            BeanValidateInfo validateInfo = (BeanValidateInfo) result.getData();
            throw new ValidatorException(validateInfo.getCode(), validateInfo.message, validateInfo.anno, result);
        }
    }
}
